﻿using Microsoft.AspNetCore.SignalR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Text.Json;
namespace SignalRChat.Signalr
{
    public class ChatHub : Hub
    {
        public async Task SendMessage(string msg)
        {
            //var jsonObject = new { chinese = "灰长标准的布咚发" };
            //msg = JsonSerializer.Serialize(value: jsonObject, options: new System.Text.Json.JsonSerializerOptions
            //{
            //    Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
            //});
            await Clients.All.SendAsync("ReceiveMessage", msg);
        }
        public async Task SendPriviteMessage(string Uid, string msg)
        {
            await Clients.User(Uid).SendAsync("ReceiveMessage", msg);
        }
    }
}
